//
//  ScatterDappManager.m
//  Bees
//
//  Created by NowYouCanSee on 2019/3/1.
//  Copyright © 2019 xiaohan. All rights reserved.
//

#import "ScatterDappManager.h"
#import "FoundModel.h"
#import "PCScatterViewController.h"
#import "WebInfoViewController.h"
#import "BaseDappViewController.h"
#import "ImportTheWalletViewController.h"
@implementation ScatterDappManager
+ (void)manager:(UIViewController*)controller forDapp:(FoundRecommendModel*)dappModel{
    if (!CURRENT_WALLET) {
        [XAlertTool alertTitle:XLocalized(@"尚未导入钱包") message:XLocalized(@"请导入钱包畅玩游戏") cancelAction:^{
            
        } sureAction:^{
            ImportTheWalletViewController *vc = [ImportTheWalletViewController new];
            [controller.navigationController pushViewController:vc animated:YES];
        }];
        return;
    }
    if (![[kUserManager haveDappAggreeId]containsObject:dappModel.modelId]) {
        [XAlertTool alertTitle:XLocalized(@"温馨提示") message:XLocalized(@"您正在跳转至第三方Dapp，确认即同意第三方Dapp的用户协议与隐私政策，由其直接并单独向您承担责任。") cancelAction:^{
            
        } sureAction:^{
            DappInfo *info = [DappInfo new];
            info.address = dappModel.redirect_url;
            info.title = dappModel.name;
            info.dappId =dappModel.modelId;
            info.imgUrl =dappModel.logo;
            info.introduction =dappModel.introduction;
            [kUserManager saveRecentlyUsed:dappModel];
            [kUserManager saveDappAggreeId:dappModel.modelId];
            BaseDappViewController *scatter = [[BaseDappViewController alloc]initWithDapp:info withRoomId:dappModel.room_id];
            [controller.navigationController pushViewController:scatter animated:YES];
        }];
   
        return;
    }
    DappInfo *info = [DappInfo new];
    info.address = dappModel.redirect_url;
    info.title = dappModel.name;
    info.dappId =dappModel.modelId;
    info.imgUrl =dappModel.logo;
    info.introduction =dappModel.introduction;
    [kUserManager saveRecentlyUsed:dappModel];
    [kUserManager saveDappAggreeId:dappModel.modelId];
    BaseDappViewController *scatter = [[BaseDappViewController alloc]initWithDapp:info withRoomId:dappModel.room_id];
    [controller.navigationController pushViewController:scatter animated:YES];
}

+ (void)manager:(UIViewController*)controller forBanner:(FoundBannerModel*)banner{
   
    if (banner.jump_type == 2) {
        WebInfoViewController *vc = [WebInfoViewController new];
        vc.gotoURL = banner.redirect_url;
        [controller.navigationController pushViewController:vc animated:YES];
    }else{
        if (ValidDict(banner.field)) {
            if ([banner.ios_go isEqualToString:NSStringFromClass(BaseDappViewController.class)]) {
                FoundBannerModel*dappId = [FoundBannerModel modelWithJSON:banner.field];
                FoundRecommendModel*dappModel = [FoundRecommendModel new];
                dappModel.redirect_url = dappId.game_url;
                dappModel.modelId = dappId.modelId;
                dappModel.name = dappId.dapp_name;
                dappModel.room_id = dappId.room_id;
                dappModel.logo = dappId.logo;
                dappModel.introduction =dappId.introduction;
                [self manager:controller forDapp:dappModel];
                return;
            }
        }
        Class Cls = NSClassFromString(banner.ios_go);
        if (Cls) {
            RootViewController*vc = [Cls new];
            [controller.navigationController pushViewController:vc animated:YES];
        }
    }
}

+ (void)jumpforDapp:(FoundRecommendModel*)dappModel{
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.35 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        DappInfo *info = [DappInfo new];
        info.address = @"https://dexeos.io/trade/";
        info.title = @"DEXEOS";
        info.dappId =@"1638200528";
        info.imgUrl =@"/uploads/image/20190319/ad9087a1ab31a02550074995f5fd297c.pn";
        dappModel.room_id = @"1638200528";
        //    [kUserManager saveRecentlyUsed:dappModel];
        //    [kUserManager saveDappAggreeId:dappModel.modelId];
        BaseDappViewController *scatter = [[BaseDappViewController alloc]initWithDapp:info withRoomId:dappModel.room_id];
        [kCurrentVC.navigationController pushViewController:scatter animated:YES];
    });
  
}

@end
